<?php


namespace App\Utils;


use GuzzleHttp\Client;

class HttpUtil
{
    static function request($method, $uri, $options)
    {
        $response = (new Client)->request($method, $uri, $options);
        $body = $response->getBody();
        return (string)$body;
    }

    static function get($uri, $query = [], $options = [])
    {
        return self::request('GET', $uri, array_merge([
            'query' => $query,
            'headers' => [
                'Content-Type' => 'application/json'
            ]
        ], $options));
    }

    static function post($uri, $body = [], $options = [])
    {
        return self::request('GET', $uri, array_merge([
            'body' => json_encode($body),
            'headers' => [
                'Content-Type' => 'application/json'
            ]
        ], $options));
    }
}